package indi.zhifa.engine.mpenhance.handler;

import indi.zhifa.engine.core.common.entity.web.RestResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 统一的异常捕获类
 */
@ControllerAdvice
@Slf4j
public class SqlExceptionHandle {

    @ExceptionHandler(value = BadSqlGrammarException.class)
    @ResponseBody
    public RestResponse handle(BadSqlGrammarException e){
        log.error("出现sql错误：\n"+e.getMessage());
        e.printStackTrace();
        return RestResponse.error("出现sql错误","错误原因为"+e.getMessage());
    }
}
